%% Simulate Disinflation in Optimal Policy Models
% by Jaromir Benes
%
% Simulate a permanent disinflation in the three types of models (a simple
% rule, discretionary policy, commitment policy). This experiment shows one
% of the possible ways how to simulate a permament change in the steady
% state of a model. It also illustrates the real cost associated with
% disinflation under different policy assumptions, measured by the
% sacrifice ratio.

%% Clear Workspace
%
% Clear workspace, close all graphics figures, clear command window, and
% check the IRIS version.

clear;
close all;
home;
irisrequired 20140319;
%#ok<*NOPTS>

%% Load Discretion and Commitment Model Objects
%
% Load all three model objects created previously in `read_model`.

load read_model.mat m1 m2 m3;

%% Set Up Input Database
%
% Disinflation is a permanent change in the steady state of the model.
% Create first a model object with a higher inflation target, `m30`, based
% on the existing model object `m3`. Assign the inflation target a higher
% value <?higherIt?>, resolve the model <?resolve?> and recompute its
% steady state <?sstate?>. Then, create a database <?higherDbase?>
% with both inflation and nominal interest rates higher by 1 %. This
% database is then used as an input database in the disinflation
% experiments below.

m3high = m3;
m3high.targ = m3high.targ + 1; %?higherIt?
m3high = solve(m3high); %?resolve?
m3high = sstate(m3high); %?sstate?

m3.pi
m3high.pi

m3.r
m3high.r


d = sstatedb(m3high,1:40); %?higherDbase?
d
d.pi
d.r

%% Simulate Disinflation
%
% Run simulations starting from a steady state with higher inflation and
% higher nominal interest rates (database `d` created above) in models
% whose steady states see low inflation and low interest rates. Run the
% simulations in all three models: `m1` (a simple policy rule), `m2`
% (optimal discretionary policy), and `m3` (optimal commitment policy).
%
% When reporting the results, add one more graph <?sacrifice?> showing the
% cumulative output gap (divided by 4 to annualize the quarterly simulation
% results). This is often called the sacrifice ratio, and it is one of the
% most important numerical characteristics of policy models. The sacrifice
% ratio is about 0.8 in all of the model versions here.

s1 = simulate(m1,d,1:40,'dbOverlay=',true);
s2 = simulate(m2,d,1:40,'dbOverlay=',true);
s3 = simulate(m3,d,1:40,'dbOverlay=',true);

dbplot(s1 & s2 & s3,0:40,{'y','pi','r','cumsum(y)/4'}); %?sacrifice?

grfun.bottomlegend('Rule','Discretion','Commitment');

grfun.ftitle('Disinflation');

%% Simulate Disinflation with Only Inflation in Loss Function
%
% Simulate the same disinflation in optimal policy models with zero weights
% on output and interest rates (`lmb1` and `lmb2`). In this kind of
% theoretical models, the central bank can disinflate immediately by
% creating a sufficient slack in real economy activity in one single
% period. The sacrifice ratio is though about double the one observed in
% the original model versions above.
%
% As in `simulate_shocks`, create two new model objects, `m2i` and `m3i`,
% based on the existing optimal policy model objects `m2` and `m3`,
% respectively. Assign the parameters `lmb1` and `lmb2` zeros
% <?zeroWeight?>, solve the model objects with these new parameters
% <?resolve2?>, and run the disinflation simulation.

m2i = m2;
m2i.lmb1 = 0; %?zeroWeight?
m2i.lmb2 = 0; %?zeroWeight?

get(m2i,'parameters')

m3i = m3;
m3i.lmb1 = 0; %?zeroWeight?
m3i.lmb2 = 0; %?zeroWeight?

m2i = solve(m2i); %?resolve2?
m3i = solve(m3i); %?resolve2?

s2i = simulate(m2i,d,1:40,'dbOverlay=',true);
s3i = simulate(m3i,d,1:40,'dbOverlay=',true);

dbplot(s2i & s3i,0:40,{'y','pi','r','cumsum(y)/4'});

grfun.bottomlegend('Discretion with Only Inflation in Loss Function', ...
    'Commitment with Only Inflation in Loss Function');

grfun.ftitle('Disinflation with Only Inflation in Loss Function');

%% Help on IRIS Functions Used in This File
%
% Use either `help` to display help in the command window, or `idoc`
% to display help in an HTML browser window.
%
%    help model
%    help model/model
%    help model/subsasgn
%    help model/solve
%    help model/sstate
%    help modle/sstatedb
%    help model/simulate
%    help dbase/dbplot
%    help grfun/bottomlegend
%    help grfun/ftitle
